package com.qipa.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 测试两个队列 连接到同一个交换器
 */
@Configuration
public class RabbitMqTopicConfig {

    //声明队列
    @Bean
    public Queue topicA(){
        return new Queue(RabbitConfig.QUEUE_A1);
    }
    //声明队列
    @Bean
    public Queue topicA2(){
        return new Queue(RabbitConfig.QUEUE_A2);
    }

    //声明交换机
    @Bean
    public TopicExchange setTopicExchangeA(){
        return new TopicExchange(RabbitConfig.EXCHANGE_A);
    }

    //交换机和队列绑定，发消息的时候只有指定ROUTINGKEY_A，QUEUE_A队列才会收到，QUEUE_B收不到
    @Bean
    public Binding bindTopicHebeiA(){
        return BindingBuilder.bind(topicA()).to(setTopicExchangeA()).with(RabbitConfig.ROUTINGKEY_A);
    }
    //交换机和队列绑定
    @Bean
    public Binding bindTopicHebeiB(){
        return BindingBuilder.bind(topicA2()).to(setTopicExchangeA()).with(RabbitConfig.ROUTINGKEY_B);
    }


}
